package com.liangzhong.model.mail
{
	import com.common.stdlib.DateUtil;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.MailType;
	import com.liangzhong.model.type.MatchType;

	/**
	 *邮件vo 
	 * @author lake
	 * 
	 */
	public class MailVo
	{
		/**
		 * 邮件ID
		 */		
		public var mailid 			:int;
		/**
		 * 邮件类型：
			1．	奖励
			2．	竞猜 --- coin 下注欧元 cashpoint 下注点券 value1 获得奖励数 strvalue1 标题 strvalue2 赔率 strvalue3 结果
			3．	任务 --- value1:物品类型 value2:物品id value3:锁定状态
			4．	比赛 --- value1:比赛类型 value2:自己进球数 value3:对手进球数  value4:获得经验 strvalue1：对手名字
			5．	抽奖
			6．	国家对抗赛奖励 value1 名次
		 */	
		public var ntype 			:int;
		/**
		 * 是否已读：1-已读，2-未读
		 */	
		public var bread 			:int;
		/**
		 * 是否已领取： 1-已领，2-未领
		 */	
		public var bget 			:int;
		/**
		 * 欧元
		 */	
		public var coin 			:int;
		/**
		 * 声望
		 */	
		public var fame 			:int;
		/**
		 * 点券
		 */	
		public var cashpoint 		:int;
		/**
		 * 数据1
		 * 奖励：物品类型
		 */	
		public var value1 			:int;
		/**
		 * 数据2
		 * 奖励：物品id
		 */	
		public var value2 			:int;
		/**
		 * 数据3
		 * 奖励：锁定状态
		 */	
		public var value3 			:int;
		/**
		 * 数据4
		 */	
		public var value4 			:int;
		/**
		 * 数据5
		 */	
		public var value5 			:int;
		/**
		 * 字符1
		 */	
		public var strvalue1 		:String = "";
		/**
		 * 字符2
		 */	
		public var strvalue2 		:String = "";
		/**
		 * 字符3
		 */	
		public var strvalue3 		:String = "";
		/**
		 *  邮件时间
		 */	
		public var time				:int;
		/**
		 *解析数据 
		 * @param $obj
		 * 
		 */		
		public function analysisData($obj:Object):void
		{
			for(var str:String in $obj)
			{
				if(this.hasOwnProperty(str))
				{
					this[str] = $obj[str];
				}
			}
		}
		/**
		 *获得描述 
		 * @return 
		 */		
		public function get desc():String
		{
			var info :String = "";
			var rewardDesc :String = "";
			rewardDesc += ",欧元"+coin;
			if(this.fame > 0)
			{
				rewardDesc += ",声望"+this.fame;
			}
			if(cashpoint > 0)
			{
				rewardDesc += ",点券"+cashpoint;
			}
			switch(ntype)
			{
				case MailType.AWARD://奖励
				{
					var goodsName :String = "";
					var goods :GoodsVo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(value1,value2);
					if(goods)
					{
						goodsName = goods.name;
					}
					info += "您获得了[" + goodsName + "]"
					break;
				}
				case MailType.GUESS://竞猜
				{
					//info += "在[西甲]巴塞罗那VS皇家马德里竞猜中您赢了！您押巴塞罗那胜，下注1000点券，赔率1.76，系统扣除5%的手续费，共获得点券123！比赛结果为巴塞罗那胜！";
					info = strvalue1 + "，";
					info += "下注" + (coin>0?coin:cashpoint) + (coin>0?"欧元":"点券") + "，";
					info += "赔率" + strvalue2 + "，";
					info += "获得" + value1 + (coin>0?"欧元":"点券") + "，";
					info += "比赛结果" + strvalue3 + "!";
					break;
				}
				case MailType.TASK://任务
				{
					var taskType :int = value1;
					var taskId	:int = value2;
					var taskItem :XML = AppData.getInstance().taskManager.getTaskItemById(taskId);
					info += "您完成了"
					if(taskItem)
					{
						info += "[" + String(taskItem.descplay) + "]任务！";
						info += "获得";
						var coin :int = int(taskItem.coin);
						var fame :int = int(taskItem.fame);
						var exp :int = int(taskItem.exp);
						if(coin>0)
						{
							info += "欧元" + coin + "";
						}
						if(fame>0)
						{
							info += "，声望" + fame + "";
						}
						if(exp>0)
						{
							info += "，经验" + exp + "";
						}
						var pid :int = int(taskItem.pid1);
						var ptype :int = int(taskItem.ntype1);
						var gvo :GoodsVo;
						if(pid > 0)
						{
							gvo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(ptype,pid);
							if(gvo)
							{
								info += "，" + gvo.name + "x1";
							}
						}
						pid = int(taskItem.pid2);
						ptype = int(taskItem.ntype2);
						if(pid > 0)
						{
							gvo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(ptype,pid);
							if(gvo)
							{
								info += "，" + gvo.name + "x1";
							}
						}
						pid = int(taskItem.pid3);
						ptype = int(taskItem.ntype3);
						if(pid > 0)
						{
							gvo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(ptype,pid);
							if(gvo)
							{
								info += "，" + gvo.name + "x1";
							}
						}
					}
					//高手过招]任务！获得欧元300000，声望4000，一个绿色球魂！";
					break;
				}
				case MailType.MATCH://比赛
				{
					var matchName :String = MatchType.getTypeName(value1);
					var resStr :String = (value2 > value3)?"打败":"输给";
					if(value2==value3)
					{
						resStr = "打平";
					}
					info += "在["+matchName+"]中，您"+value2+"："+value3+ resStr +"了["+strvalue1+"]，获得了经验"+value4+"";
					info += rewardDesc;
					info += "";
					break;
				}
				case MailType.COUNTRY_AW://国家对抗赛奖励 
				{
					info = "您在上轮国家挑战赛中获得了第"+value1+"名,奖励"+this.fame+"声望！"
					break;
				}
			}
			return info;
		}
		/**
		 *获取时间字符串 
		 * @return 
		 * 
		 */		
		public function get timeStr():String
		{
			var date :Date = new Date(time*1000);
			return DateUtil.objToShowTimeFormat(date);
		}
	}
}